﻿using MVCDemo.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MVCDemo.DAL
{
    //DropCreateDatabaseIfModelChanges 如果实体发生变化，则删除重建数据库 并插入测试数据： 开发阶段使用
    //Initializer 使用是在web.config contexts
    public class AccountInitializer:DropCreateDatabaseIfModelChanges<AccountContext>
    {
        protected override void Seed(AccountContext context)
        {
            //base.Seed(context);

            var sysUsers = new List<SysUser>
            {
                new SysUser{UserName="Tom",Email="100@qq.com", Password="1"},
                new SysUser{UserName="Jerry",Email="200@qq.com", Password="2"}
            };

            sysUsers.ForEach(s => context.SysUsers.Add(s));
            context.SaveChanges();

            var sysRoles = new List<SysRole>
            {
                new SysRole{RoleName="Administrator",RoleDesc="超级管理员"},
                new SysRole{RoleName="General User",RoleDesc="普通"}
            };
            sysRoles.ForEach(x => context.SysRoles.Add(x));
            context.SaveChanges();

        }

    }
}